package cn.bsb.service.backstage;

import java.util.Date;
import java.util.List;
  
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.bsb.dao.RecommendMapper;
import cn.bsb.pojo.Article;
 
@Service
public class RecommendService {

	@Autowired
	private RecommendMapper recommend;
	
		//以推荐文章列表
		public PageInfo<Article> recommend(int pageNum,int pageSize){
			PageHelper.startPage(pageNum, pageSize);
			List<Article> list = recommend.recommendList();
			PageInfo<Article> page = new PageInfo<Article>(list);
			return page;
		}
		public List<Article> ReTitle(String title){
			return recommend.reSelectList(title);
		}
		
		//推荐文章列表
		public PageInfo<Article> good(int pageNum,int pageSize){
			PageHelper.startPage(pageNum, pageSize);
			List<Article> list = recommend.goodList();
			PageInfo<Article> page = new PageInfo<Article>(list);
			return page;
		}
		public List<Article> Title(String title){
			return recommend.reTitleList(title);
		}
		/*
		 * 取消推荐
		 */
		public boolean deleteRe(long id) {
			boolean flag = false;
			if(recommend.deleteRe(id) != 0) {
				if(recommend.updater(id)!= 0) {
					flag = true;
				}
			}
			return flag;
		}
		//推荐文章
		public boolean addrecommend(long dev_user_id,long article_id,long backend_user_id,Date time) {
			boolean flag = false;
			if(recommend.addrecommend(dev_user_id,article_id,backend_user_id,time) != 0) {
				if(recommend.updatere(article_id)!= 0) {
					flag = true;
				}
			}
			return flag;
		}
}
